/* eslint-disable no-mixed-operators */
import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.partShipmentId)
        requiredFields.push(
            formatMessage({
                id: 'validator.partShipmentId',
                defaultMessage: '备件箱单发票编号'
            })
        );
    if(!data || !data.invoiceFee)
        requiredFields.push(
            formatMessage({
                id: 'validator.invoiceFee',
                defaultMessage: '报关金额'
            })
        );
    if(!data || !data.carrierId)
        requiredFields.push(
            formatMessage({
                id: 'validator.carrierId',
                defaultMessage: '货代名称'
            })
        );
    if(!data || data.isMagnetic !== 0 && data.isMagnetic !== 1 && data.isMagnetic !== true && data.isMagnetic !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isMagnetic',
                defaultMessage: '是否磁检'
            })
        );
    if(!data || data.isChemical !== 0 && data.isChemical !== 1 && data.isChemical !== true && data.isChemical !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isChemical',
                defaultMessage: '是否化工鉴定'
            })
        );
    if(!data || data.isPL !== 0 && data.isPL !== 1 && data.isPL !== true && data.isPL !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isPL',
                defaultMessage: '是否有装箱单'
            })
        );
    if(!data || data.isLoading !== 0 && data.isLoading !== 1 && data.isLoading !== true && data.isLoading !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isLoading',
                defaultMessage: '是否有装柜图'
            })
        );
    if(!data || data.isWarehousingAndAddress !== 0 && data.isWarehousingAndAddress !== 1 && data.isWarehousingAndAddress !== true && data.isWarehousingAndAddress !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isWarehousingAndAddress',
                defaultMessage: '是否有进仓通知与地址'
            })
        );
    if(!data || data.isExpressDocuments !== 0 && data.isExpressDocuments !== 1 && data.isExpressDocuments !== true && data.isExpressDocuments !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isExpressDocuments',
                defaultMessage: '是否有快递面单'
            })
        );
    if(!data || data.isRandomFiles !== 0 && data.isRandomFiles !== 1 && data.isRandomFiles !== true && data.isRandomFiles !== false)
        requiredFields.push(
            formatMessage({
                id: 'validator.isRandomFiles',
                defaultMessage: '是否有随机文件'
            })
        );
    if(!data || data.isLoadingCabinet === true) {
        if(!data || !data.loadingTime)
            requiredFields.push(
                formatMessage({
                    id: 'validator.loadingTime',
                    defaultMessage: '装柜时间'
                })
            );
        if(!data || !data.loadingQuantity)
            requiredFields.push(
                formatMessage({
                    id: 'validator.loadingQuantity',
                    defaultMessage: '装柜数量'
                })
            );
    }
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};

export const outboundValidator = data => {
    const requiredFields = [];
    if(!data || !data.outboundDate)
        requiredFields.push(
            formatMessage({
                id: 'validator.outboundDate',
                defaultMessage: '出库时间'
            }));
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
